

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--加入jstl标签库--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>用户列表页面</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->

    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <link rel="stylesheet" href="./css/fileinput.min.css">

    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
            crossorigin="anonymous"></script>
    <!-- jsp= html + servlet -->
    <script src="./js/fileinput.min.js"></script>
    <style>
        /*th, td {
            text-align: center
        }
*/
        .a {
            position: absolute;
            left: 42%;
            top: 30%;
            width: 250px;
            height: 225px;
            border: 1px solid darkgreen;
            bord-radius: 10px;
            background: aliceblue;
            text-align: center;
        }

    </style>
</head>

<body style="background-image:url('images/5.jpg')">
<div class="a">
    <h1>注册界面</h1>
    账号：<input type="text" name="buyername" ><br><%--style="margin-bottom: 4px;"--%>
    密码：<input type="password" name="password" ><br>
    电话：<input type="text" name="buyernum" ><br>
    地址：<input type="text" name="buyerplace"><br>

    <!--按钮-->
    <input type="button" value="注册" id="btn" onclick="addBuyer()">
    <input type="button" value="取消" id="btn2"><br>
</div>

<!-- 导航  开始 -->
<div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">商品购物管理</a>
                </div>
                <div>
                    <!--向左对齐-->
                    <ul class="nav navbar-nav navbar-left">
                        <li class="dropdown">
                            <a href="home.jsp" class="dropdown-toggle">
                                首页
                                <b class="caret"></b>
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="/Test/shopping.jsp" class="dropdown-toggle">商品</a>
                        </li>
                        <li class="dropdown">
                            <a href="buyerregister.jsp" class="dropdown-toggle">注册</a>
                        </li>
                        <li class="dropdown">
                            <a href="buyerlogin.jsp" class="dropdown-toggle">登录</a>
                        </li>
                        <li class="dropdown">
                            <a href="login.html" class="dropdown-toggle">后台管理</a>
                        </li>
                    </ul>
                    <!--向右对齐 -->
                    <ul class="nav navbar-nav navbar-right">
                    </ul>
                </div>
            </div>
        </nav>
    </div>
    <div class="col-md-1"></div>
</div>
<!-- 导航  结束 -->
</body>
<script>
   /* <!-- 取消按钮跳转-->*/
    document.getElementById("btn2").onclick = function() {
        location.href = "home.jsp";
    }
</script>
<script>
    //添加用户
    function addBuyer() {
        //获取输入框的值
        var buyername = $("input[name=buyername]").val();
        var password = $("input[name=password]").val();
        var buyernum = $("input[name=buyernum]").val();
        var buyerplace = $("input[name=buyerplace]").val();

        if (!buyername) {
            alert("账号不能为空！");
            return;
        }
        if (!password) {
            alert("密码不能为空！");
            return;
        }
        if (!buyernum) {
            alert("电话不能为空！");
            return;
        }
        if (!buyerplace) {
            alert("地址不能为空！");
            return;
        }

        //组装数据
        var obj = {}
        //obj.id = id;
        obj.buyername = buyername;
        obj.password = password;
        obj.buyernum = buyernum;
        obj.buyerplace = buyerplace;

        $.ajax({

            url: "/Test/buyer?method=addBuyer",//请求路径
            data: {
                buyername: buyername,
                password: password,
                buyernum: buyernum,
                buyerplace: buyerplace,
            },//请求数据
            type: "POST",//请求方式
           // dataType: "json",//请求数据类型
            // contentType: "application/json",//返回数据类型
            success: function (data) {
                console.log(data);
                data = JSON.parse(data);//把后台的数据处理为JSON格式
                if (data.code == "0000") {
                    alert("注册成功！");
                    location.href = "home.jsp";
                } else {
                    alert("注册失败！");
                }
            }
        })

    }
</script>
</html>
